Skip to content

security: red-team audit hardening#7

Merged
jkyberneees merged 5 commits into
mainfrom
fix/security-audit-redteam
Jun 21, 2026
Merged

security: red-team audit hardening#7
jkyberneees merged 5 commits into
mainfrom
fix/security-audit-redteam

Conversation

@jkyberneees

@jkyberneees jkyberneees commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Comprehensive security hardening pass following the red-team audit (findings document kept out of the mergeable tree per project convention).

Key fixes

  • Client IP extraction: uses the socket peer IP (server.requestIP) as the only trusted direct address and walks X-Forwarded-For from right to left through validated trusted proxies.
  • Proxy header sanitization: strips hop-by-hop / Connection headers, attacker-controlled X-Forwarded-*, Cookie, Authorization, and Proxy-Authorization; rewrites Host and sets trusted forwarded headers.
  • JWT hardening: enforces the exp claim and minimum HMAC key length per algorithm.
  • Load balancer: validates health-check URL schemes/hosts, bounds response reads, uses secure randomness, generates sticky-session cookies server-side, clamps health-check intervals, and adds incrementConnections/decrementConnections.
  • Cluster manager: allow-lists environment variables forwarded to workers and worker script paths.
  • TLS/ops: applies hardening options to Bun.serve, validates redirects, removes committed TLS key material from the working tree, pins CI deps, and prevents prototype pollution in config merging.
  • Tests: generate self-signed TLS certificates at runtime so CI does not depend on ignored examples/*.pem.

Public API changes documented

  • ClusterConfig.allowedEnvVars and workerScriptAllowlist
  • HealthCheckConfig.allowedSchemes, allowedHosts, method, expectedBody, failureThreshold, successThreshold, minHealthyTargets
  • LoadBalancer.selectTarget(request, clientIP?) and incrementConnections / decrementConnections

Verification

  • bun run build
  • bun test802 pass / 0 fail
  • bun run format:check
  • GitHub Actions tests workflow ✅

VProtocol verdict

Posted as a PR comment: HumanReviewRecommended (η = 0.804, ρ = 0.15; driven by PR size cap and monoculture correlation penalty).

Remaining manual step

CRIT-1 recommends rewriting git history to fully remove the old examples/key.pem / examples/cert.pem from history (e.g. git filter-repo / BFG). They are deleted and ignored in this branch but still exist in earlier commits.

…luster, ops

- Harden client IP extraction against X-Forwarded-For spoofing

- Sanitize upstream proxy headers (hop-by-hop, auth, X-Forwarded-*)

- Enforce JWT exp claim and minimum HMAC key length

- Secure load balancer health checks and sticky sessions

- Remove committed TLS private key from working tree; add .gitignore rules

- Prevent prototype pollution via safe config merging

- Apply TLS hardening options to Bun.serve

- Update CI and docs with security hardening

- Align tests with new secure defaults; 802/802 tests pass
Comment thread src/security/security-headers.ts Dismissed
…l certificate

- Update ClusterConfig reference with allowedEnvVars and workerScriptAllowlist

- Update HealthCheckConfig reference with failure/success thresholds, allowedSchemes, allowedHosts, method, expectedBody

- Fix LOAD_BALANCING.md threshold names and add restrict-targets best practice

- Add verification-certificate.json and VERIFICATION.md from VProtocol run

Verdict: HumanReviewRecommended (size cap + monoculture ρ)
The audit findings document is intentionally kept out of the mergeable

tree; it can be regenerated locally and is now gitignored.
…examples/*.pem

- Add node-forge dev dependency and test/fixtures/tls-certs.ts helper

- Refactor tls-manager.test.ts and tls-integration.test.ts to use generated certs

- Fixes CI failures where examples/cert.pem and examples/key.pem are gitignored
Remove VERIFICATION.md and verification-certificate.json from tracked files;

they are now gitignored. The verification summary will be posted as a PR comment.
@jkyberneees jkyberneees merged commit 407486d into main Jun 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants